package com.zyong.design.pattern.flyweight.case1;

import java.util.HashMap;
import java.util.Map;

/**
 * @program: zyong-design-pattern
 * @ClassName: FlyWeightFactory
 * @author: zyong
 * @create: 2024-04-05 00:00
 */
public class FlyWeightFactory {
    private static Map<String, FlyWeight> map = new HashMap<>();

    public static FlyWeight getShareInstance(String key) {
        if (!map.containsKey(key)) {
            map.put(key, new ConcreteFlyWeight());
        }

        return map.get(key);
    }

    public static FlyWeight getUnSharedInstance() {
        return new UnsharedConcreteFlyWeight();
    }
}
